#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1e5+5;
struct cmp
{
	bool operator ()(const pair<LL,int> &Ta,const pair<LL,int> &Tb){
		if(Ta.first == Tb.first) return Ta.second > Tb.second;
		else return Ta.first>Tb.first;
	}	
};
int Q,T,N,M,cnt,base;
set<pair<int,LL>,cmp> q;
map<LL,int> mp;
LL sum[maxn];
LL turn(int x,int y){
	int mx = min(x,N-x+1),my = min(y,M-y+1),ms = min(mx,my)-1;
	LL ret = sum[ms];
	int len_m = M-ms*2-1,len_n = N-ms*2-1,rn = N-ms,rm = M-ms;
	if(x == ms+1)return ret + y-ms;
	else if(y == rm)return ret + len_m + x-ms;
	else if(x == rn)return ret + len_m + len_n + rm-y+1; 
	else return ret + len_m + len_n + len_m + rn-x+1;
}
void testId(){
	for(int i=1;i<=N;++i){
		for(int j=1;j<=M;++j){
			printf("%lld%c",turn(i,j),j==M?'\n':' ');
		}
	}
	return;
}
void cal(LL id,int v){
	if(!mp.count(id)){
		mp[id] = 0;
		q.insert(make_pair(0,id));
	}

	auto it = q.find(make_pair(mp[id],id));
	q.erase(it);
	q.insert(make_pair(it->first-v,it->second));

	mp[id] -= v;
	base += v;
}
int main(){
	scanf("%d",&T);
	while(T--){
		scanf("%d%d",&N,&M);
		assert(N%2==0&&M%2==0);
		cnt = min(N/2,M/2);
		for(int i=1;i<=cnt;++i){
			sum[i] = 2*(N+M-4*i+2);
			sum[i] += sum[i-1];
		}
		base = 0,mp.clear(),q.clear();
		scanf("%d",&Q);
		while(Q--){
			int o,x,y,v;
			scanf("%d",&o);
			assert(1<=o&&o<=3);
			if(o==1){
				scanf("%d%d%d",&x,&y,&v);
				assert(x>=1&&x<=N&&y>=1&&y<=M&&abs(v)<=1e4);
				LL id = turn(x,y);
				cal(id,v);
			}	
			else if(o==2){
				LL id;
				scanf("%lld%d",&id,&v);
				assert(id<=1LL*N*M&&id>=1&&abs(v)<=1e4);
				cal(id,v);
			}
			else{
				auto it = q.begin();
				int ans = 0;
				if(it != q.end())ans = max(ans,it->first);
				printf("%d\n",base+ans);
			}
		}
	}
	return 0;
}